using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Services.TfsAlert.AppCode;
using Microsoft.Services.TfsAlert.AppCode.NotificationEvents;

using Microsoft.Services.TfsAlert.Core;

namespace Microsoft.Services.TfsAlert.UnitTests.NotificationEvents
{
    [TestClass]
    public class NotificationEventFactory_UnitTests
    {
        ApplicationHelpers _applicationHelpers = null;

        [TestInitialize]
        public void TestInitialize()
        {
            _applicationHelpers = new ApplicationHelpers();
        }



        [TestMethod]
        public void CanCreateCheckinEventInstance()
        {
            string xmlRepresentation = @"<?xml version=""1.0"" encoding=""utf-16""?><CheckinEvent xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><AllChangesIncluded>true</AllChangesIncluded><Subscriber>HQ\csell5</Subscriber><CheckinNotes><CheckinNote xsi:type=""NameValuePair"" name=""Code Reviewer"" val="""" /><CheckinNote xsi:type=""NameValuePair"" name=""Performance Reviewer"" val="""" /><CheckinNote xsi:type=""NameValuePair"" name=""Security Reviewer"" val="""" /></CheckinNotes><PolicyFailures /><CheckinInformation /><Artifacts><Artifact xsi:type=""ClientArtifact"" ArtifactType=""Changeset"" ServerItem=""""><Url>http://websvr:8080/VersionControl/Changeset.aspx?artifactMoniker=21&amp;webView=true</Url></Artifact><Artifact xsi:type=""ClientArtifact"" ArtifactType=""VersionedItem"" Item=""New Text Document.txt"" Folder=""$/Test"" TeamProject=""Test"" ItemRevision=""21"" ChangeType=""edit"" ServerItem=""$/Test/New Text Document.txt""><Url>http://websvr:8080/VersionControl/VersionedItem.aspx?artifactMoniker=Test%252fNew%2bText%2bDocument.txt%26changesetVersion%3d21%26deletionId%3d0%26webView%3dtrue</Url></Artifact></Artifacts><Title>Test Changeset 21</Title><ContentTitle>Changeset 21</ContentTitle><Owner>HQ\csell5</Owner><Committer>HQ\csell5</Committer><Number>21</Number><CreationDate>2/24/2006 6:06:17 PM</CreationDate><Comment /><TimeZone>Central Standard Time</TimeZone><TimeZoneOffset>-06:00:00</TimeZoneOffset><TeamProject>Test</TeamProject></CheckinEvent>";

            NotificationEventFactory notificationEventFactory = new NotificationEventFactory();
            INotificationEvent notificationEvent = notificationEventFactory.CreateEvent( xmlRepresentation );

            Assert.IsNotNull( notificationEvent );
            Assert.IsInstanceOfType( notificationEvent, typeof( CheckinEvent ) );
        }
		

        [TestMethod]
        public void CanCreateWorkItemChangedEventInstance()
        {
            WorkItemChangedEvent eventObject = new WorkItemChangedEvent();

            string xmlRepresentation = _applicationHelpers.SerializeXml( eventObject );

            NotificationEventFactory notificationEventFactory = new NotificationEventFactory();
            INotificationEvent notificationEvent = notificationEventFactory.CreateEvent( xmlRepresentation );

            Assert.IsInstanceOfType( notificationEvent, typeof( WorkItemChangedEvent ) );
        }

        [TestMethod]
        public void CanCreateMembershipChangedEventInstance()
        {
            MembershipChangedEvent eventObject = new MembershipChangedEvent();

            string xmlRepresentation = _applicationHelpers.SerializeXml( eventObject );

            NotificationEventFactory notificationEventFactory = new NotificationEventFactory();
            INotificationEvent notificationEvent = notificationEventFactory.CreateEvent( xmlRepresentation );

            Assert.IsInstanceOfType( notificationEvent, typeof( MembershipChangedEvent ) );
        }

        [TestMethod]
        public void CanCreateBuildStatusChangedEventInstance()
        {
            BuildStatusChangeEvent eventObject = new BuildStatusChangeEvent();

            string xmlRepresentation = _applicationHelpers.SerializeXml( eventObject );

            NotificationEventFactory notificationEventFactory = new NotificationEventFactory();
            INotificationEvent notificationEvent = notificationEventFactory.CreateEvent( xmlRepresentation );

            Assert.IsInstanceOfType( notificationEvent, typeof( BuildStatusChangeEvent ) );
        }

        [TestMethod]
        public void CanCreateBuildCompletionEventInstance()
        {
            BuildCompletionEvent eventObject = new BuildCompletionEvent();

            string xmlRepresentation = _applicationHelpers.SerializeXml( eventObject );

            NotificationEventFactory notificationEventFactory = new NotificationEventFactory();
            INotificationEvent notificationEvent = notificationEventFactory.CreateEvent( xmlRepresentation );

            Assert.IsInstanceOfType( notificationEvent, typeof( BuildCompletionEvent ) );
        }

        [TestMethod]
        public void CanCreateBranchMovedEventInstance()
        {
            BranchMovedEvent eventObject = new BranchMovedEvent();

            string xmlRepresentation = _applicationHelpers.SerializeXml( eventObject );

            NotificationEventFactory notificationEventFactory = new NotificationEventFactory();
            INotificationEvent notificationEvent = notificationEventFactory.CreateEvent( xmlRepresentation );

            Assert.IsInstanceOfType( notificationEvent, typeof( BranchMovedEvent ) );
        }

        [TestMethod]
        public void CanCreateBranchMoveEventInstance()
        {
            AclChangedEvent eventObject = new AclChangedEvent();

            string xmlRepresentation = _applicationHelpers.SerializeXml( eventObject );

            NotificationEventFactory notificationEventFactory = new NotificationEventFactory();
            INotificationEvent notificationEvent = notificationEventFactory.CreateEvent( xmlRepresentation );

            Assert.IsInstanceOfType( notificationEvent, typeof( AclChangedEvent ) );
        }
    }
}